<template>
<view>
<!-- pages/ucenter/recruit/recruit.ttml -->
<!--<import src="/templates/login/index.wxml"></import>-->

<view class="space">
	<icon type size color></icon>
	<view class="text" bold>基础信息</view>
</view>

<view class="space-text" v-if="!isNull">
	<view class="text-info">
		<text>完善人员信息，能让老板充分了解您或您的队伍</text>
	</view>
	<view class="button">
		<button type="primary" size="mini" @tap="basic_info"> 去完善
		</button>
	</view>
</view>
<view class="list" :data-id="info.id" v-if="isNull">
	<view class="list-title">姓名：{{info.uname}}</view>
	<view class="list-title">性别：{{info.sex}}</view>
	<view class="list-title">民族：{{info.nation}}</view>
	<view class="list-title" v-if="isShow">工种：{{info.workType}}</view>
	<view class="list-title">手机：{{info.phone}}</view>
	<view class="list-title">所在地区：{{info.area}}</view>
	<view class="list-title">自我介绍：{{info.self}}</view>
	<button class="updata-text" @tap="updata_text">编辑</button>
</view>

<view v-if="isShow">
	<view class="space">
		<icon type size color></icon>
		<view class="text">人员信息</view>
	</view>
	<view class="space-text" v-if="!personnel">
		<view class="text-info">
			<text>完善人员信息，能让老板充分了解您或您的队伍</text>
		</view>
		<view class="button">
			<button type="primary" size="mini" @tap="personnel_info"> 去完善
			</button>
		</view>
	</view>
	<view class="list" :data-id="personnel.id" v-else>
		<view class="list-title">工龄：{{personnel.workAge}}</view>
		<view class="list-title">家乡：{{personnel.home}}</view>
		<view class="list-title">熟练度：{{personnel.proficiency}}</view>
		<view class="list-title">人员构成：{{personnel.composition}}</view>
		<view class="list-title">人数：{{personnel.num}}</view>
		<button class="updata-text" @tap="updata_personnel">编辑</button>
	</view>
</view>

<view v-if="isShow">
	<view class="space">
		<icon type size color></icon>
		<view class="text">项目经验</view>
	</view>
	<view class="space-text" v-if="projectIsNull">
		<view class="text-info">
			<text>添加项目经验，可提升老板对您的信任程度</text>
		</view>
		<view class="button">
			<button type="primary" size="mini" @tap="projectFun"> 添加项目经验
			</button>
		</view>
	</view>
	<view v-if="!projectIsNull">
		<view v-for="(item, index) in project" :key="index" class="list" :data-id="item.id">
			<view class="list-title">项目名称：{{item.pojectTitle}}</view>
			<view class="list-title">开工时间：{{item.startTime}}</view>
			<view class="list-title">完工时间：{{item.endTime}}</view>
			<view class="list-title">所在地区：{{item.area}}</view>
			<view class="list-title">项目详情：{{item.projectDetail}}</view>
			<text class="delete" :data-id="item.id" @tap="deleteProject">删除</text>
		</view>
		<button class="updata-text" @tap="updata_project">编辑</button>
	</view>
</view>

<view v-if="isShow">
	<view class="space">
		<icon type size color></icon>
		<view class="text">职业技能</view>
	</view>
	<view class="space-text" v-if="skillsIsNull">
		<view class="text-info">
			<text>添加职业技能，用实力证明您的能力</text>
		</view>
		<view class="button">
			<button type="primary" size="mini" @tap="occupation"> 添加职业技能
			</button>
		</view>
	</view>

	<view v-if="!skillsIsNull">
		<view v-for="(item, index) in skills" :key="index" class="list" :data-id="item.id">
			<view class="list-title">职业技能：{{item.skillName}}</view>
			<view class="list-title">领取证书时间：{{item.time}}</view>
			<text class="delete" :data-id="item.id" @tap="deleteSkill">删除</text>
		</view>
		<button class="updata-text" @tap="updata_skills">编辑</button>
	</view>
</view>

<view class="share_but" v-if="isShow">
	<button size="default" @tap="shareTo"> 分享我的名片
	</button>
</view>

<view v-if="!apiUserInfoMap" class="userinfo">
	<block data-type="template" data-is="apifmLogin" data-attr="ttlogin: ttlogin">
	<view class="apifmLogin" :hidden="ttlogin">
		<view class="s-b">
			<view class="s-l-b">
				<image src="/static/images/nologin.png"></image>
				<text>授权登录</text>
			</view>
			<view class="s-t-b">
				<view class="s-t-i">
					<text>·</text>
					请授权小程序登录
				</view>
				<view class="s-t-i">
					<text>·</text>
					我们不会公布您的这些信息
				</view>
				<view class="s-t-i">
					<text>·</text>
					只是为了给您提供更好的服务
				</view>
			</view>
			<button class="l" open-type="getUserInfo" @getuserinfo="processLogin">允许
			</button>
			<button class="c" @tap="cancelLogin" type="default">暂不登录
			</button>
		</view>
	</view>
</block>
</view>
</view>
</template>

<script>
// pages/ucenter/recruit/recruit.js
let app = getApp();
import search from "../../../components/cmap/cmap";

export default {
  data() {
    return {
      isShow: false,
      isNull: true,
      personnelIsNull: true,
      projectIsNull: true,
      skillsIsNull: true,
      ttlogin: false,
      info: {
        uname: "",
        area: "",
        phone: "",
        gender: "",
        nation: "",
        workType: "",
        self: "",
        sex: ""
      },
      personnel: {
        proficiency: "",
        composition: "",
        workAge: "",
        home: "",
        num: ""
      },
      project: [],
      skills: [],
      apiUserInfoMap: ""
    };
  },

  components: {
    search
  },
  props: {},
  onLoad: function (options) {
    var that = this;
    var userInfoParam = uni.getStorageSync('userInfo');
    console.log(userInfoParam);

    if (userInfoParam) {
      that.setData({
        ttlogin: true,
        apiUserInfoMap: userInfoParam
      });
    } else {
      that.setData({
        ttlogin: false
      });
    }

    uni.request({
      url: `${app.globalData.baseUrl}/user/info/${uni.getStorageSync("openid")}`,
      // 目标服务器url
      method: 'GET',
      dataType: 'json',
      header: {
        'content-type': 'application/json'
      },
      success: res => {
        console.log('查询成功', res.data);

        if (res.data.message === "成功") {
          that.setData({
            info: res.data.dataMap.data,
            isNull: true
          });
        } else {
          that.setData({
            isNull: false
          });
        }
      }
    });
    uni.request({
      url: `${app.globalData.baseUrl}/mallappletbackstage/personnel-info/getInfo/${uni.getStorageSync("openid")}`,
      // 目标服务器url
      method: 'GET',
      dataType: 'json',
      header: {
        'content-type': 'application/json'
      },
      success: res => {
        console.log('人员信息', res.data);

        if (res.data.message === "查询成功") {
          that.setData({
            personnel: res.data.dataMap.data,
            personnelIsNull: true
          });
        } else {
          that.setData({
            personnelIsNull: false
          });
        }
      }
    });
    uni.request({
      url: `${app.globalData.baseUrl}/mallappletbackstage/project-experience/getProject/${uni.getStorageSync("openid")}`,
      // 目标服务器url
      method: 'GET',
      dataType: 'json',
      header: {
        'content-type': 'application/json'
      },
      success: res => {
        console.log('项目经验', res.data);

        if (res.data.dataMap.data.length > 0) {
          that.setData({
            project: res.data.dataMap.data,
            projectIsNull: false
          });
        } else {
          that.setData({
            projectIsNull: true
          });
        }
      }
    });
    uni.request({
      url: `${app.globalData.baseUrl}/mallappletbackstage/skills-certificate/getSkills/${uni.getStorageSync("openid")}`,
      // 目标服务器url
      method: 'GET',
      dataType: 'json',
      header: {
        'content-type': 'application/json'
      },
      success: res => {
        console.log('职业技能', res.data);

        if (res.data.dataMap.data.length > 0) {
          that.setData({
            skills: res.data.dataMap.data,
            skillsIsNull: false
          });
        } else {
          that.setData({
            skillsIsNull: true
          });
        }
      }
    });
    uni.request({
      url: `${app.globalData.baseUrl}/mallappletbackstage/is-show/select/isShow`,
      // 目标服务器url
      method: 'GET',
      header: {
        'content-type': 'application/json'
      },
      success: res => {
        console.log('是否伪装', res.data.dataMap.data);

        if (res.data.dataMap.data.isShow === 1) {
          this.setData({
            isShow: true
          });
        } else {
          this.setData({
            isShow: false
          });
        }
      }
    });
  },

  onShareAppMessage(res) {},

  methods: {
    onShwo: function () {
      uni.request({
        url: `${app.globalData.baseUrl}/user/info/${uni.getStorageSync("openid")}`,
        // 目标服务器url
        method: 'GET',
        dataType: 'json',
        header: {
          'content-type': 'application/json'
        },
        success: res => {
          console.log('查询成功', res.data);
          that.setData({
            info: res.data.dataMap.data
          });
        }
      });
      uni.request({
        url: `${app.globalData.baseUrl}/mallappletbackstage/personnel-info/getInfo/${uni.getStorageSync("openid")}`,
        // 目标服务器url
        method: 'GET',
        dataType: 'json',
        header: {
          'content-type': 'application/json'
        },
        success: res => {
          console.log('查询成功', res.data);
          that.setData({
            personnel: res.data.dataMap.data
          });
        }
      });
      uni.request({
        url: `${app.globalData.baseUrl}/mallappletbackstage/project-experience/getProject/${uni.getStorageSync("openid")}`,
        // 目标服务器url
        method: 'GET',
        dataType: 'json',
        header: {
          'content-type': 'application/json'
        },
        success: res => {
          console.log('项目经验', res.data);
          that.setData({
            project: res.data.dataMap.data
          });
        }
      });
      uni.request({
        url: `${app.globalData.baseUrl}/mallappletbackstage/skills-certificate/getSkills/${uni.getStorageSync("openid")}`,
        // 目标服务器url
        method: 'GET',
        dataType: 'json',
        header: {
          'content-type': 'application/json'
        },
        success: res => {
          console.log('职业技能', res.data);
          that.setData({
            skills: res.data.dataMap.data
          });
        }
      });
      uni.request({
        url: `${app.globalData.baseUrl}/mallappletbackstage/is-show/select/isShow`,
        // 目标服务器url
        method: 'GET',
        header: {
          'content-type': 'application/json'
        },
        success: res => {
          console.log('是否伪装', res.data.dataMap.data);

          if (res.data.dataMap.data.isShow === 1) {
            this.setData({
              isShow: true
            });
          } else {
            this.setData({
              isShow: false
            });
          }
        }
      });
    },
    basic_info: function () {
      uni.navigateTo({
        url: "/pages/ucenter/uinfo/uinfo"
      });
    },
    personnel_info: function () {
      uni.navigateTo({
        url: "/pages/ucenter/personnel/personnel"
      });
    },
    projectFun: function () {
      uni.navigateTo({
        url: "/pages/ucenter/project/project"
      });
    },
    occupation: function () {
      uni.navigateTo({
        url: "/pages/ucenter/skill/skill"
      });
    },
    updata_text: function () {
      uni.navigateTo({
        url: "/pages/ucenter/uinfo/uinfo"
      });
    },
    updata_personnel: function () {
      uni.navigateTo({
        url: "/pages/ucenter/personnel/personnel"
      });
    },
    updata_project: function () {
      uni.navigateTo({
        url: "/pages/ucenter/project/project"
      });
    },
    updata_skills: function () {
      uni.navigateTo({
        url: "/pages/ucenter/skill/skill"
      });
    },
    cancelLogin: function () {
      uni.navigateBack({
        delta: 1,

        success(res) {
          console.log(`${res}`);
        },

        fail(res) {
          console.log(`navigateBack调用失败`);
        }

      });
    },
    //授权登录绑定按钮
    processLogin: function (e) {
      app.globalData.globalHandleLogin(e);
      this.setData({
        apiUserInfoMap: app.globalData.userInfoData
      });
      this.onLoad();
    },
    deleteProject: function (e) {
      console.log('获取的id值', e.currentTarget.dataset.id);
      uni.request({
        url: `${app.globalData.baseUrl}/mallappletbackstage/project-experience/deleteProject/${e.currentTarget.dataset.id}`,
        // 目标服务器url
        method: 'DELETE',
        header: {
          'content-type': 'application/x-www-form-urlencoded'
        },
        success: res => {
          var constant = res.data.message;
          console.log('删除成功', constant);
          uni.navigateTo({
            url: '/pages/ucenter/recruit/recruit'
          });
        }
      });
    },
    deleteSkill: function (e) {
      console.log('获取的id值', e.currentTarget.dataset.id); //${app.baseUrl}

      uni.request({
        url: `${app.globalData.baseUrl}/mallappletbackstage/skills-certificate/deleteSkill/${e.currentTarget.dataset.id}`,
        // 目标服务器url
        method: 'DELETE',
        header: {
          'content-type': 'application/x-www-form-urlencoded'
        },
        success: res => {
          var constant = res.data.message;
          console.log('删除成功', constant);
          uni.navigateTo({
            url: '/pages/ucenter/recruit/recruit'
          });
        }
      });
    },
    shareTo: function () {
      uni.navigateTo({
        url: '/pages/card/index/index'
      });
    },

    onShareTimeline() {}

  }
};
</script>
<style>
/* @import "../../../templates/login/index.css"; */

.space {
  height: 90rpx;
  background: #F4F5F9;
}
.text {
  text-align:center;
  font-weight:650;
  font-size: 34rpx;
  line-height: 25rpx;
}
.space-text{
  height: 200rpx;
}
.text-info{
  text-align:center;
  padding: 32rpx;
  color: rgb(190, 190, 190);
}
.button{
  text-align:center;
  padding: 13rpx;
}
.version {
  width:100vw;
	font-size: 24rpx;
	text-align: center;  
  padding: 32rpx;
}
.updata-text{
  color: rgb(15, 30, 247);
}
.list {
  width: 95%;
  margin: 2.5%;
  border-bottom: solid 1px #e6e6ee;
  background: #fff;
  padding: 5rpx 10rpx;
}
.delete{
  color: red;
}
</style>